package com.example.acer.widgettest_118lz;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv;
    private EditText et;
    private Button btngetext, btnsetimg;
    private ImageButton ibtn;
    private ImageView iv;
    private RadioButton rbnan,rbnv;
    private RadioGroup rg;
    private CheckBox cblan,cbzu,cbyou;
    private Button btngetgender,btngetfun;
    private String strfun="";//保存兴趣的字符串

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    private void init() {
        tv = (TextView) findViewById(R.id.textView);
        et = (EditText) findViewById(R.id.editText);
        btngetext = (Button) findViewById(R.id.button);
        btnsetimg = (Button) findViewById(R.id.button2);
        ibtn = (ImageButton) findViewById(R.id.imageButton);
        iv = (ImageView) findViewById(R.id.imageView);
        ibtn.setOnClickListener(this);
        btngetext.setOnClickListener(this);
        btnsetimg.setOnClickListener(this);
        //获取八个控件
        rbnan=(RadioButton)findViewById(R.id.radioButton2);
        rbnv=(RadioButton)findViewById(R.id.radioButton);
        rg=(RadioGroup)findViewById(R.id.radiogroup);
        cblan=(CheckBox)findViewById(R.id.checkBox3);
        cbzu=(CheckBox)findViewById(R.id.checkBox2);
        cbyou=(CheckBox)findViewById(R.id.checkBox);
        btngetfun=(Button)findViewById(R.id.button4);
        btngetgender=(Button)findViewById(R.id.button5);
        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId)
                {
                    case R.id.radioButton:
                        tv.setText("女");
                        break;
                    case R.id.radioButton2:
                        tv.setText("男");
                        break;
                }
            }
        });
        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)//checkBox被勾选
                    strfun+="篮球+";
                else//checkBox未被勾选
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);
            }
        });
        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)//checkBox被勾选
                    strfun += "足球+";
                else//checkBox未被勾选
                    strfun = strfun.replace("足球+", "");
                tv.setText(strfun);
            }
        });
                cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked)//checkBox被勾选
                            strfun += "游泳+";
                        else//checkBox未被勾选
                            strfun = strfun.replace("游泳+", "");
                        tv.setText(strfun);
                    }
                });
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button:
                String str = et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2:
                iv.setImageResource(R.drawable.z123);
                break;
            case R.id.imageButton:
                Intent intent = new Intent(MainActivity.this, NewActivity.class);
                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);
                startActivity(intent);
                break;
            case R.id.button4://获取性别
                if(rbnan.isChecked())
                    tv.setText("男");
                if(rbnv.isChecked())
                    tv.setText("女");
                break;
            case R.id.button5://获取兴趣
                   String msg="";
                if(cblan.isChecked())
                    msg+="篮球";
                if(cbzu.isChecked())
                    msg+="足球";
                if(cbyou.isChecked())
                    msg+="游泳";
                tv.setText(msg);
                break;
        }
    }
    }